function th5datacreate()

v = version('-release');
if strcmp(v,'2006b')
    fprintf('\tH5DATACREATE not available on 2006b.\n');
    return
end

fprintf('\tTesting H5DATACREATE...  ');
test_gzip;
test_complex;
test_double;
test_size_maxsize;

fprintf('OK\n');

%--------------------------------------------------------------------------
function test_gzip()

hfile = 'a.h5';

fid = h5filecreate(hfile);
dsid = h5datacreate(fid,'/DS1','chunk_size',[10 10],'Size',[20 30],'compression',5);
H5D.close(dsid);
H5F.close(fid);

fid = H5F.open(hfile,'H5F_ACC_RDONLY','H5P_DEFAULT');
dsetId = H5D.open(fid,'/DS1');
dcpl = H5D.get_create_plist(dsetId);

[filter flags cd_values name] = H5P.get_filter(dcpl,0);
if ~strcmp(name,'deflate')
	error('did not verify gzip compression');
end
if cd_values ~= 5
	error('did not verify gzip compression level');
end



%--------------------------------------------------------------------------
function test_size_maxsize()

hfile = 'a.h5';

fid = h5filecreate(hfile);
dsid = h5datacreate(fid,'/DS1','chunk_size',[10 10],'Size',[20 30],'max_size',[40 60]);
H5D.close(dsid);
H5F.close(fid);

fid = H5F.open(hfile,'H5F_ACC_RDONLY','H5P_DEFAULT');
dsetId = H5D.open(fid,'/DS1');
spaceId = H5D.get_space(dsetId);

[n,dims,maxdims] = H5S.get_simple_extent_dims(spaceId); %#ok<ASGLU>

% make it vertical so that this can pass on 2007b.  What were they thinking?
dims = flipud(dims(:));
maxdims = flipud(maxdims(:));
if ( dims(1) ~= 20 ) || ( dims(2) ~= 30 ) 
    error('Did not create a 20x30 double precision dataset');
end
if ( maxdims(1) ~= 40 ) || ( maxdims(2) ~= 60 ) 
    error('Did not create a 20x30 double precision dataset');
end




%--------------------------------------------------------------------------
function test_double()

hfile = 'a.h5';

fid = h5filecreate(hfile);
dsid = h5datacreate(fid,'/DS1','Size',[20 30]);
H5D.close(dsid);
H5F.close(fid);

fid = H5F.open(hfile,'H5F_ACC_RDONLY','H5P_DEFAULT');
dsetId = H5D.open(fid,'/DS1');
spaceId = H5D.get_space(dsetId);

[n,dims] = H5S.get_simple_extent_dims(spaceId); %#ok<ASGLU>

% make it vertical so that this can pass on 2007b.  What were they thinking?
dims = flipud(dims(:));
if ( dims(1) ~= 20 ) || ( dims(2) ~= 30 ) 
    error('Did not create a 20x30 double precision dataset');
end


%--------------------------------------------------------------------------
function test_complex()

hfile = 'a.h5';

fid = h5filecreate(hfile);
dsid = h5datacreate(fid,'/DS1','Size',[20 30],'type','complex');
H5D.close(dsid);
H5F.close(fid);

md=hdf5info('a.h5');
if (~isequal(md.GroupHierarchy.Datasets.Dims,[20,30]))
    error('Dataset has wrong size');
end
if (~isequal(md.GroupHierarchy.Datasets.Datatype.Class,'H5T_COMPOUND'))
    error('Dataset is improper type');
end

